#pragma once

#include <concurrent_queue.h>


class CSelectModelLib :
	public INetworkLib
{
	ON_CONNECT_FUNCTOR		m_onConnectFunctor;
	ON_ACCEPT_FUNCTOR		m_onAcceptFunctor;	
	ON_DISCONNECT_FUNCTOR	m_onDisconnectFunctor;
	ON_RECV_FUNCTOR			m_onRecvFunctor;

	Concurrency::concurrent_queue<SOCKET>	m_connectedSocketQueue;

	IAsyncSendQueue*		m_pAsyncSendQueue;
private:
	static UINT __stdcall	acceptWorkerThread( void* pArguments );
	static UINT __stdcall	recvWorkerThread( void* pArguments );
	bool					Send(SOCKET socket);	
public:
	CSelectModelLib(void);
	virtual ~CSelectModelLib(void);

	virtual bool	Initialize(ON_CONNECT_FUNCTOR onConnect
							, ON_ACCEPT_FUNCTOR onAccept
							, ON_DISCONNECT_FUNCTOR onDisconnect
							, ON_RECV_FUNCTOR onRecv		
							) override;

	virtual bool	Connect(const std::tstring& ip, WORD port) override;

	virtual bool	Send(SOCKET socket, IStreamBuffer& stream) override;

	

	virtual bool	Disconnect(SOCKET socket) override;

	virtual bool	Listen(const std::tstring& ip, WORD port, int backlog) override;

	virtual void	Release() override;
	
};

